/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.commands.connection;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Generalization;

import com.cea.papyrus.core.helper.ModelerHelper;
import com.cea.papyrus.diagraminterchange2.di2.GraphEdge;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;
import com.cea.papyrus.diagraminterchange2.di2.Uml1SemanticModelBridge;

/**
 * 
 */
public class GeneralizationCreateCommand extends ConnectionCreateCommand
		implements IConnectionCreateCommand {

	/**
	 * 
	 * 
	 * @param type 
	 * @param location 
	 * @param source 
	 */
	public GeneralizationCreateCommand(GraphElement source, Object type, Point location) {
		super(source, type, location);
	}
	
	/**
	 * 
	 * 
	 * @return 
	 */
	protected GraphEdge createGraphEdge() {
		Element umlLink=ModelerHelper.getFactory().createUMLElement(Generalization.class,getSourceElement());	
		return  (GraphEdge)ModelerHelper.getFactory().createGraphElement(umlLink, getOwner(), null, null);
	}
	
	/**
	 * 
	 * 
	 * @param bridge 
	 * @param targetBridge 
	 * @param sourceBridge 
	 */
	@Override
	public void disconnectBussinessModel(Uml1SemanticModelBridge bridge, Uml1SemanticModelBridge sourceBridge, Uml1SemanticModelBridge targetBridge) {
		ModelerHelper.getFactory().deconnect(type, getSourceElement(), getTargetElement(), getEdgeElement());
		ModelerHelper.getFactory().removeElement(type, getEdgeElement(), getSourceElement());
	}

	/**
	 * 
	 * 
	 * @param bridge 
	 * @param targetBridge 
	 * @param sourceBridge 
	 */
	@Override
	public void reconnectBussinessModel(Uml1SemanticModelBridge bridge, Uml1SemanticModelBridge sourceBridge, Uml1SemanticModelBridge targetBridge) {
		// replace getUMLParent by getSourceElement() (parent = source for generalization)
		ModelerHelper.getFactory().addUMLElement(type, getEdgeElement(), getSourceElement());
		ModelerHelper.getFactory().connect(type,getSourceElement(), getTargetElement(),getEdgeElement());
		
	}

}
